﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Sunflower : PlantBase
{
    private float createSunTime=24;

    private float goldNeedTime = 1;
    // Start is called before the first frame update
    void Start()
    {
        
    }

    



    public void CreateSun()
    {
        StartCoroutine(DoCreateSun());
        
    }

    IEnumerator DoCreateSun()
    {
        float currTime = 0;
        
        currTime += 0.05f;
        float lerp;
        while (currTime<goldNeedTime)
        {
            yield return new WaitForSeconds(0.05f);
            lerp = currTime / goldNeedTime;
            currTime += 0.05f;
            spriteRenderer.color = Color.Lerp(Color.white, new Color(1, 0.6f, 0), lerp);
        }
        spriteRenderer.color = Color.white;
        Sunlight sun = GameObject.Instantiate<GameObject>(GameManager.Instance.GameConf.Sun, transform.position, Quaternion.identity, transform).GetComponent<Sunlight>();
        sun.Jump();
    }

    protected override void OnInitForPlace()
    {
        InvokeRepeating("CreateSun",5, createSunTime);
    }
}
